/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tracnghiem.dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

/**
 *
 * @author tjtyler
 */
public class ConnectionManagement {

    private static String username;
    private static String password;
    private static Connection con;

    public static void setPassword(String password) {
        ConnectionManagement.password = password;
    }

    public static void setUsername(String username) {
        ConnectionManagement.username = username;
    }
    

    public static boolean checkConnection() {
        String connstr = "jdbc:odbc:DETAITRACNGHIEM";
        try {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        } catch (java.lang.ClassNotFoundException e) {
            System.err.print("Class Driver khong tim thay: ");
        }
        try {
            DriverManager.getDriver(connstr);
            con = DriverManager.getConnection(connstr, username, password);
            Statement stmt = con.createStatement();

        } catch (SQLException ex) {
            return false;
        }
        return true;
    }

    public static Connection getConnection() {
        return con;
    }
}
